package com.example.girl.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.girl.bean.Fankui;
import com.example.girl.bean.WenTiFanKuiLX;
import com.example.girl.http.APIRetrofit;
import com.example.girl.http.APIService;
import com.example.girl.util.SpfUtils;
import com.example.lbstest.R;
import com.kaopiz.kprogresshud.KProgressHUD;
import com.king.base.util.LogUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;


/**
 * 问题反馈
 */

public class Feedback_Activity extends AppCompatActivity {


    @BindView(R.id.img_back)
    RelativeLayout imgBack;
    @BindView(R.id.textView8)
    TextView textView8;
    @BindView(R.id.yuyue)
    TextView yuyue;
    @BindView(R.id.name)
    TextView name;

    @BindView(R.id.shijian_lay)
    LinearLayout shijianLay;
    @BindView(R.id.editText)
    EditText editText;
    @BindView(R.id.activity_seetting)
    LinearLayout activitySeetting;
    List<String> ccList = new ArrayList<String>();
    List<WenTiFanKuiLX.DataBean> data;
    String ids;
    @BindView(R.id.lianxifangshi)
    TextView lianxifangshi;
    @BindView(R.id.et_lianxi)
    EditText etLianxi;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_feedback);
        ButterKnife.bind(this);
        String phone = (String) SpfUtils.get(Feedback_Activity.this, "Phone", "");
        etLianxi.setText(phone);
      }
    KProgressHUD dialog;

    public void showdialog() {
        dialog = KProgressHUD.create(Feedback_Activity.this)
                .setStyle(KProgressHUD.Style.SPIN_INDETERMINATE)
                .setLabel("正在上传中，请稍候")
                .setCancellable(true)
                .setAnimationSpeed(2)
                .setDimAmount(0.5f)
                .show();
    }

    @OnClick({R.id.img_back, R.id.textView8})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.textView8:
                String s = editText.getText().toString();
                String names = name.getText().toString();
                if (TextUtils.isEmpty(names)) {
                    Toast.makeText(this, "请输入反馈名称！", Toast.LENGTH_SHORT).show();
                    return;

                }
                if (TextUtils.isEmpty(s)) {
                    Toast.makeText(this, "请输入反馈信息！", Toast.LENGTH_SHORT).show();
                    return;

                }

                showdialog();

                APIRetrofit.getInstance()
                        .create(APIService.class)
                        .feedback_add(names,s)
                        .subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread())

                        .subscribe(new Observer<Fankui>() {
                            @Override
                            public void onCompleted() {
                                LogUtils.e("onCompleted");

                            }

                            @Override
                            public void onError(Throwable e) {
                                LogUtils.e(e);
                                Toast.makeText(Feedback_Activity.this, "网络错误!", Toast.LENGTH_SHORT).show();

                                if (dialog!=null) {
                                    dialog.dismiss();
                                }
                            }

                            @Override
                            public void onNext(Fankui girlResult) {
                                LogUtils.e(girlResult.toString());
                                Toast.makeText(Feedback_Activity.this, "添加留言成功！", Toast.LENGTH_SHORT).show();
                                if (dialog!=null) {
                                    dialog.dismiss();
                                }
                                finish();
                            }
                        });
                break;
        }
    }
}
